//
//  TKYDataConnectionView.m
//  StationHouseHelper
//
//  Created by apple on 2018/7/26.
//  Copyright © 2018年 铁科院. All rights reserved.
//

#import "TKYDataConnectionView.h"
@interface TKYDataConnectionView()
@property (nonatomic, strong) UIView *bottomLineView;
@end
@implementation TKYDataConnectionView
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.selectedBtn];
        [self addSubview:self.contentLabel];
        [self addSubview:self.deleteButton];
        [self addSubview:self.bottomLineView];
        [self addSubview:self.imageV];
        
        __weak typeof(self) weakSelf = self;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf).with.offset(kWidthScale *10);
            make.top.equalTo(weakSelf).with.offset(kHeightScale *12);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *100);
        }];
        [self.selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self.contentView).with.offset(20);
            make.top.equalTo(weakSelf).with.offset(kHeightScale *12);
            make.right.equalTo(self.imageV.mas_left).with.offset(-kWidthScale*7);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *40);
        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self.contentView).with.offset(20);
            make.top.equalTo(weakSelf.titleLabel.mas_bottom).with.offset(kHeightScale *2);
            make.left.equalTo(weakSelf).with.offset(kWidthScale *20);
            make.bottom.equalTo(weakSelf).with.offset(0);
            make.height.mas_equalTo(kHeightScale *40);
            make.width.mas_equalTo(kWidthScale *200);
        }];
        //
        [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            //make.left.equalTo(self.contentView).with.offset(20);
            make.top.equalTo(self.selectedBtn.mas_bottom).with.offset(kHeightScale *2);
            make.right.equalTo(self).with.offset(-kWidthScale *20);
            // make.bottom.equalTo(self.contentView).with.offset(-12);
            make.height.mas_equalTo(kHeightScale *20);
            make.width.mas_equalTo(kWidthScale *40);
        }];
        
        [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).with.offset(-kWidthScale*20);
            make.top.equalTo(self).with.offset(15);
            make.height.mas_equalTo(kWidthScale*10);
            make.width.mas_equalTo(kWidthScale*10);
        }];
        
        [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(kWidthScale*10);
            make.right.equalTo(self).with.offset(-kWidthScale*10);
            make.bottom.equalTo(self).with.offset(-kHeightScale *1);
            make.height.mas_equalTo(kWidthScale*1);
        }];
    }
    return self;
}

- (UILabel *)titleLabel{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.text = @"资料关联";
        _titleLabel.font = Font(12);
    }
    return _titleLabel;
}

- (UILabel *)contentLabel{
    if (_contentLabel == nil) {
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.font = Font(12);
        _contentLabel.numberOfLines = 0;
        //_contentLabel.backgroundColor = [UIColor redColor];
    }
    return _contentLabel;
}

- (UIButton *)selectedBtn{
    if (_selectedBtn == nil) {
        _selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        //[_selectedBtn setTitle:@"" forState:UIControlStateNormal];
        //_selectedBtn.backgroundColor = [UIColor redColor];
        [_selectedBtn setTitle:@"请选择" forState:UIControlStateNormal];
        [_selectedBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _selectedBtn.titleLabel.textAlignment = NSTextAlignmentRight;
        _selectedBtn.titleLabel.font = Font(12);
        [_selectedBtn addTarget:self action:@selector(selectButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectedBtn;
}

- (UIButton *)deleteButton{
    if (_deleteButton == nil) {
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteButton.titleLabel.font = Font(14);
        [_deleteButton setTitle:@"删除" forState:UIControlStateNormal];
        [_deleteButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [_deleteButton addTarget:self action:@selector(deleteButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteButton;
}

- (UIView *)bottomLineView{
    if (_bottomLineView == nil) {
        _bottomLineView = [[UIView alloc]init];
        _bottomLineView.backgroundColor = kMainColour;
    }
    return _bottomLineView;
}

- (UIImageView *)imageV{
    if (_imageV == nil) {
        _imageV = [[UIImageView alloc]init];
        _imageV.image = [UIImage imageNamed:@"select_btn"];
    }
    return _imageV;
}

- (void)selectButtonClick:(UIButton *)button{
    if (self.seletetedButtonBlock) {
        self.seletetedButtonBlock(button);
    }
    NSLog(@"点击了选择按钮");
}


- (void)deleteButtonClick:(UIButton *)button{
    if (self.deleteButtonBlock) {
        self.deleteButtonBlock(button);
    }
}


@end
